package cn.message.web;

import cn.itcast.pojo.order;
import cn.itcast.pojo.withdraw;
import cn.itcast.util.OutputStringController;
import cn.message.service.IWithdrawService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 提现的控制器类
 * @author 郭智超
 * @create 2020-04-03 16:42
 */
@Slf4j
@RestController
@RequestMapping(value="/dhn/message",produces="text/html;charset=UTF-8")
public class WithdrawController {

    @Resource
    private IWithdrawService withdrawService;

    @Resource
    OutputStringController osc;

    @ResponseBody
    @RequestMapping("/getAllWithdraw")
    public String getAllWithdraw(@RequestBody Map<String,String> map){
        String results= "";

        Map<String, Object> resultMap = withdrawService.getAllWithdraw(map);

        //获取所有提现记录
        Object withdrawList = resultMap.get("withdrawList");

        //获取符合查询条件的总记录条数
        int count = (int)resultMap.get("count");

        if(withdrawList == null){
            results = osc.resultFailure("no", "");
            log.debug("查询所有提现记录失败");
        }
        else {
            results = osc.resultSuccess("yes",withdrawList, count);
            log.debug("查询所有提现记录成功");
        }
        return results;
    }
    @ResponseBody
    @RequestMapping("/getOrder")
    public String getOrder(@RequestBody Map<String,Object> map ,order order){
        String results= "";
        //获取前台提交的数据
        Integer page = (Integer)map.get("page");
        Integer limit = (Integer)map.get("limit");
        String  openId = (String) map.get("openId");
        Map<String, Object> resultMap = withdrawService.getOrderById(page, limit, openId, order);

        //获取该用户所有的订单记录
        Object orderList = resultMap.get("orderList");

        //获取符合查询条件的总记录条数
        int count = (int)resultMap.get("count");

        if(orderList == null){
            results = osc.failure("该用户还没有下过单");
        }
        else {
            results = osc.resultSuccess("yes",orderList, count);
        }
        return results;
    }



    @ResponseBody
    @RequestMapping("/sendCheck")
    public String sendCheck(@RequestBody Map<String,Object> map){
        String results= "";
        //获取前台提交的数据
        Integer id = (Integer) map.get("id");
        Boolean aBoolean = withdrawService.checkWithdraw(id);
        if(!aBoolean) {
            results = osc.failure("系统异常，审核通过失败");
        }else {
            results = osc.success("审核成功，该提现申请已通过");
        }
        return results;
    }

    @ResponseBody
    @RequestMapping("/lostEffect")
    public String lostEffect(@RequestBody Map<String,Object> map){
        String results= "";
        //获取前台提交的数据
        Integer id = (Integer) map.get("id");
        Boolean aBoolean = withdrawService.lostEffect(id);
        if(!aBoolean) {
            results = osc.failure("系统异常，审核失效失败");
        }else {
            results = osc.success("审核失效成功，该提现申请已失效");
        }
        return results;
    }
}
